<?php

/**
 * This is the model class for table "volunteer".
 *
 * The followings are the available columns in table 'volunteer':
 * @property integer $volunteer_id
 * @property string $volunteer_code
 * @property integer $volunter_people_id
 *
 * The followings are the available model relations:
 * @property MissionAssignment[] $missionAssignments
 * @property People $volunterPeople
 * @property VolunteerHistory[] $volunteerHistories
 */
class Volunteer extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Volunteer the static model class
	 */
	  public function getVolunteer()
	  {
	  	return $this->volunteer_code.'- '.$this->volunterPeople->volunteerName;
	  }
	  public function getVolunteerName()
	  {
		return $this->volunterPeople->volunteerName;
	  }
	  
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'volunteer';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('volunteer_code, volunter_people_id', 'required'),
			array('volunter_people_id', 'numerical', 'integerOnly'=>true),
			array('volunteer_code', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('volunteer_id, volunteer_code, volunter_people_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'missionAssignments' => array(self::HAS_MANY, 'MissionAssignment', 'assignment_volunteer_id'),
			'volunterPeople' => array(self::BELONGS_TO, 'People', 'volunter_people_id'),
			'volunteerHistories' => array(self::HAS_MANY, 'VolunteerHistory', 'volunteer_history_volunteer_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'volunteer_id' => 'Volunteer',
			'volunteer_code' => 'Volunteer Code',
			'volunter_people_id' => 'Volunter People',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('volunteer_id',$this->volunteer_id);
		$criteria->compare('volunteer_code',$this->volunteer_code,true);
		$criteria->compare('volunter_people_id',$this->volunter_people_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}